home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / Prograph Reference Manual.sit / Prograph Reference Manual / Prograph Reference 8-End.rsrc / TEXT_143.txt < prev    next >
Text File  |  1995-10-26  |  25KB  |  554 lines

  1.  Appendix II
  2.  
  3.  C Code Usage
  4.  
  5.  t General Remarks
  6.  
  7.  t Writing XPrims
  8.  
  9.  t Writing XCode
  10.  
  11. *521*
  12.  
  13. Both the Prograph interpreter and the Prograph compiler allow you to import code written in C. There are two different formats for writing imported C code. One is used for writing external primitives (XPrims), which can be included in the Prograph environment, much like XCMDs are included in HyperCard. The other format is used for writing external code (XCode) which is linked by the compiler into your final application. 
  14.  
  15. XPrims allow you to define Prograph primitives which can be used in both interpreted and compiled code. XCode allows greater access to Prograph language elements such as methods, attributes and persistents. However, XCode can be used only in compiled code.
  16.  
  17. Both XPrims and XCode may be written in either MPW C or THINK C. THINK C object extensions may be used in XCode. 
  18.  
  19.  
  20. _______________________________________
  21. NOTE:    The Prograph C Interfaceerface allows you to access existing C  libraries from the Prograph interpreter and compiler. It is available directly from Prograph International. 
  22. ---------------------------------------
  23.  
  24.  
  25. t    General Remarks  *521*
  26.  
  27. In this section we discuss matters which are pertinent to both XPrims and XCode written in either MPW C or THINK C. A good understanding of the topics covered in this section is necessary before writing C code to be imported by Prograph.
  28.  
  29.  Naming Conventions  *522*
  30.  
  31. In compiled code the interface between Prograph and C is provided through a set of naming conventions. These conventions allow you to access and define Prograph language elements such as methods, attributes, and persistents in C. 
  32.  
  33. In compiled code, primitives use the same naming convention as universal methods (in fact, the Prograph compiler makes no distinction between primitives and universal methods). In order for XPrims to run in interpreted and compiled code they must be named according to the naming conventions for universal methods.
  34.  
  35. A universal method is a function with a name of the form U_id. A persistent is a global variable with a name of the form P_id.  Each Prograph class has a default instance which is a global variable of the form C_class__A_default. Class attributes are global variables of the form C_class__A_id. In Prograph there are four types of class methods:   simple (or plain), initialization, get and set. Class methods are C functions with names of the form:   C_class__M_id (simple), C_class__N_ (initialization), C_class__G_id (get), and C_class__S_id (set). In C, two other types of class methods may be defined:   default get methods and default set methods which have the forms C_class__g_id and C_class__s_id respectively. A Prograph class has an associated class identifier which is a global variable of the form C_id__.
  36.  
  37. Any non-alphanumeric character in a name must be replaced by the two-character, hexadecimal ASCII code and delimited by underscores. For example, the universal method point-in-rect? is represented as U_point_2D_in_2D_rect_3F_ ( 2D and 3F being the ASCII representations of '-' and '?' respectively).
  38.  
  39. In XCode, Prograph classes and class methods may be accessed directly through THINK classes.
  40.  
  41. The use of these naming conventions is discussed in detail in the section on XCode. 
  42.  
  43.  Prograph Data Types *522*
  44.  
  45. In this section the Prograph data types are discussed in general terms. Actual C definitions of the data types, which differ between interpreted XPrims, compiled XPrims, and XCode, are given in later sections.
  46.  
  47. For portability all Prograph data types are based upon the following set of fundamental C types. *523*
  48.  
  49. typedef char Int1;          /* integer 1 byte */
  50. typedef short Int2;         /* integer 2 byte*/
  51. typedef long Int4;          /* integer 4 byte*/
  52.  
  53. typedef unsigned char Nat1;      /* natural 1 byte */
  54. typedef unsigned short Nat2;     /* natural 2 byte */
  55. typedef unsigned long Nat4;      /* natural 4 byte */
  56.  
  57. typedef float Real4;         /* real 4 byte */
  58. typedef short double Real8;      /* real 8 byte */
  59. typedef double Real10;        /* real 10 byte */
  60.  
  61. typedef Nat2 Bool;          /* boolean 2 byte */
  62.  
  63. Prograph uses eight basic data types and one special data type called the NULL type. All of the data types are implemented as handles except the NULL type which is implemented as a zero value. *523*
  64.  
  65. Type    Interpreted XPrims    Compiled XPrims    XCode 
  66.  
  67. C_boolean TRUE = 1, FALSE = 0    TRUE = 1, FALSE = 0    TRUE = 1, FALSE = 0    
  68.  
  69. C_instance 0 to 65534 attributes    232 - 1 attributes    232 - 1 attributes    
  70.  
  71. C_integer signed four-byte integer    signed four-byte integer    signed four-byte integer    
  72.  
  73. C_list 0 to 65535 list elements    232 - 1 list elements    232 - 1 list elements    
  74.  
  75. C_none no value    no value    no value    
  76.  
  77. C_real 10-byte SANE extended real    10-byte SANE extended real    10-byte SANE extended real    
  78.  
  79. C_string 0 to 65535 characters    232 - 1 characters    232 - 1 characters    
  80.  
  81. C_undefined  no value    no value    no value    
  82.  
  83. With the exception of the NULL type all Prograph data types have three fields in common:   type, save and use. *523*
  84.  
  85. The type field identifies the data type. The contents of this field should never be accessed directly; use the supplied functions IsType, HasType and GetRefLevel or the supplied macro INCLASS (described below) instead.*524*
  86.  
  87. The save field is used by Prograph during loading and saving of files, and when cycles in data linkage need to be detected. The save field is for internal use by Prograph only.
  88.  
  89. The use field contains the data item窶冱 窶忖se count窶, which is the number of references to this item. The section 窶弑se Counts窶 below explains this important concept. 
  90. An abstract data type, C_object, which has only type, save and use fields, is provided for declarations of variables of undetermined type. 
  91.  
  92. The C_none and C_undefined data types consist only of a type, save and use field.
  93.  
  94. The C_boolean type has a value field that contains one to indicate TRUE, or zero for FALSE.*524*
  95.  
  96. The C_integer type has a value field that contains any 32-bit integer.
  97.  
  98. The C_real has a value field that contains any valid SANE (10-byte) extended real number.  (For details on the SANE extended real, see The Apple Numerics manual.)
  99. Prograph lists are implemented as arrays (rather than as linked lists). The C_list type contains a length field indicating the number of elements in the list. A length of ten indicates ten values in the list, and a length of zero indicates no entries, or the empty list. 
  100.  
  101. The length field is followed by the data field, a variable-length array of four-byte entries. Each entry, or slot, in the data array is either a handle to a data item or NULL. 
  102.  
  103. Prograph treats the first element of a list as index one, but C treats the first element as index zero. A primitive written in C should therefore subtract one from an index passed in from Prograph as an argument. Similarly, an index returned as output should have the value one added to it.
  104.  
  105. Strings are represented by the C_string type. C_strings are similar in structure to C_lists except that, instead of an array of four-byte slots, they have an array of one-byte characters in the field text. A C_string with length zero is the empty string.*524*
  106.  
  107. Instances of user-defined classes are implemented as type C_instance. The C_Instance type contains a field attrs which is an array of data items.  The array elements correspond, in order, to the instance attributes defined for the class.  As with lists, this array is zero-based.
  108.  
  109. Macintosh Data Types *525*
  110.  
  111. Macintosh data types differ between compiled code and interpreted code. In this section we discuss what is common to both. Actual C definitions of the structures are given in the following section. 
  112.  
  113. Macintosh-dependent data types are stored in structures each of which has a type, save, use and value field. The value field of each Macintosh data type has a different underlying C type. For example, a C_Point has a value field of type Point and a C_EventRecord has a value field of type EventRecord.
  114.  
  115. The structure C_ABlock is available for macintosh data of an unsupported type. The value field of C_ABlock is an array of bytes. The primitive new-block is provided for the creation of ABlocks.
  116.  
  117. The data types C_Ptr and C_Handle have value fields which are macintosh pointers and handles respectively. These may be pointers and handles to any type of macintosh data. C_Ptr and C_Handle also have a field which indicates the type of the data which is pointed to. 
  118.  
  119. The HasType and GetRefLevel supplied functions (described below) allow you to determine the the level of indirection and the underlying macintosh type of any Macintosh data item. 
  120.  
  121. Data Types in XPrims *525*
  122.  
  123. This section describes C declarations of the Prograph data types for XPrims. Although the declarations differ between interpreted and compiled code, these differences will be transparent if only common fields are used. 
  124.  
  125. The save and use fields are two bytes in interpreted code but four bytes in compiled code. The same is true of the length fields of the C_string and C_list types. The C_instance data type has two extra fields in interpreted code. Macintosh types have several differences; declarations are shown for C_Point, C_Ptr and C_Handle.
  126.  
  127. Note that all Prograph data types are declared as pointers but are implemented as handles. This is to preserve compatibility with THINK C object extensions. The following example shows how a parameter of type C_object is declared.*525*
  128.  
  129.  U_sample_20_method( anObject )
  130.  C_object *anObject;        /* anObject is a Handle */
  131.  {
  132.  ...
  133.  
  134. Each type has a structure name of the form CS_name. This is required in interpreted XPrim code by the supplied functions which create data items.
  135.  
  136. XPrim interpreted code declarations:  *526*
  137.  
  138.  
  139.  typedef struct      /* C_object - INTERPRETED XPrims */
  140.  {
  141.   Int2    type;    /* internal use only */
  142.   Nat2    save;    /* internal use only */
  143.   Nat2    use;    /* number of references */
  144.  }  *C_object;
  145.  typedef struct      /* C_none - INTERPRETED XPrims */    
  146.  {
  147.   Int2    type;    /* internal use only */
  148.   Nat2    save;    /* internal use only */
  149.   Nat2    use;    /* number of references */
  150.  } CS_none, *C_none;
  151.  
  152.  typedef struct      /* C_undefined - INTERPRETED XPrims */
  153.  {
  154.   Int2    type;    /* internal use only */
  155.   Nat2    save;    /* internal use only */
  156.   Nat2    use;    /* number of references */
  157.  } CS_undefined, *C_undefined;
  158.  
  159.  typedef struct      /* C_boolean - INTERPRETED XPrims */
  160.  {
  161.   Int2    type;    /* internal use only */
  162.   Nat2    save;    /* internal use only */
  163.   Nat2    use;    /* number of references */
  164.   Bool    value;
  165.  } CS_boolean, *C_boolean;
  166.  
  167.  typedef struct      /* C_integer - INTERPRETED XPrims */
  168.  {
  169.   Int2    type;    /* internal use only */
  170.   Nat2    save;    /* internal use only */
  171.   Nat2    use;    /* number of references */
  172.   Int4     value;
  173.  } CS_integer, *C_integer;
  174.  
  175.  typedef struct      /* C_real - INTERPRETED XPrims */
  176.  {
  177.   Int2    type;    /* internal use only */
  178.   Nat2    save;    /* internal use only */
  179.   Nat2    use;    /* number of references */
  180.   Real10    value;
  181.  } CS_real, *C_real;
  182.  typedef struct      /* C_list - INTERPRETED XPrims */
  183.  {
  184.   Int2     type;    /* internal use only */
  185.   Nat2     save;    /* internal use only */
  186.   Nat2     use;    /* number of references */
  187.   Nat2     length; /* length of list  */
  188.   C_object    *data[];
  189.  } CS_list, *C_list;
  190.  typedef struct      /* C_string - INTERPRETED XPrims */
  191.  {
  192.   Int2    type;    /* internal use only */
  193.   Nat2    save;    /* internal use only */
  194.   Nat2    use;    /* number of references */
  195.   Nat2    length; /* length of string */
  196.   Nat1    text[];
  197.  } CS_string, *C_string;
  198.  
  199.  typedef struct      /* C_instance - INTERPRETED XPrims */
  200.  {
  201.   Int2    type;    /* internal use only */
  202.   Nat2    save;    /* internal use only */
  203.   Nat2    use;    /* number of references */
  204.   Nat2    size;    /* Interpreted only (# of attributes +1)*/
  205.   Handle     class;    /* Interpreted only */
  206.   C_object    *attrs[];
  207.  } CS_instance, *C_instance;
  208.  
  209.  typedef struct    /* C_Point - INTERPRETED XPrims */
  210.  {
  211.   Int2    type;     /* internal use only  */       
  212.   Nat2    save;     /* internal use only */      
  213.   Nat2    use;     /* number of references */      
  214.   Nat2    size;     /* Interpreted only */     
  215.   Int2    mactype; /* Interpreted only */
  216.   Point    value;
  217.  } CS_Point, *C_Point;
  218.  
  219.  typedef struct    /* C_Ptr - INTERPRETED XPrims */
  220.  {
  221.   Int2    type;     /* internal use only  */       
  222.   Nat2    save;     /* internal use only */      
  223.   Nat2    use;     /* number of references */      
  224.   Nat2    size;     /* Interpreted only */     
  225.   Int2    mactype; /* Interpreted only */
  226.   Ptr    value;
  227.  } CS_Ptr, *C_Ptr;
  228.  
  229.  typedef struct    /* C_Handle - INTERPRETED XPrims */
  230.  {
  231.   Int2    type;     /* internal use only  */       
  232.   Nat2    save;     /* internal use only */      
  233.   Nat2    use;     /* number of references */      
  234.   Nat2    size;     /* Interpreted only */     
  235.   Int2    mactype; /* Interpreted only */
  236.   Handle    value;
  237.  } CS_Handle, *C_Handle;
  238.  
  239. XPrim compiled code declarations:    *528*
  240.  
  241.  typedef struct      /* C_object - COMPILED XPrims */
  242.  {
  243.   Int2    type;    /* internal use only */
  244.   Nat4    save;    /* internal use only */
  245.   Nat4    use;    /* number of references */
  246.  }  *C_object;
  247.  
  248.  typedef struct      /* C_none - COMPILED XPrims */    
  249.  {
  250.   Int2    type;    /* internal use only */
  251.   Nat4    save;    /* internal use only */
  252.   Nat4    use;    /* number of references */
  253.  } *C_none;
  254.  
  255.  typedef struct      /* C_undefined - COMPILED XPrims */
  256.  {
  257.   Int2    type;    /* internal use only */
  258.   Nat4    save;    /* internal use only */
  259.   Nat4    use;    /* number of references */
  260.  } *C_undefined;
  261.  
  262.  typedef struct      /* C_boolean - COMPILED XPrims */
  263.  {
  264.   Int2    type;    /* internal use only */
  265.   Nat4    save;    /* internal use only */
  266.   Nat4    use;    /* number of references */
  267.   Bool    value;
  268.  } *C_boolean;
  269.  
  270.  typedef struct      /* C_integer - COMPILED XPrims */
  271.  {
  272.   Int2    type;    /* internal use only */
  273.   Nat4    save;    /* internal use only */
  274.   Nat4    use;    /* number of references */
  275.   Int4    value;
  276.  } *C_integer;
  277.  
  278.  typedef struct      /* C_real - COMPILED XPrims */
  279.  {
  280.   Int2    type;    /* internal use only */
  281.   Nat4    save;    /* internal use only */
  282.   Nat4    use;    /* number of references */
  283.   Real10    value;
  284.  } *C_real;
  285.  typedef struct      /* C_list - COMPILED XPrims */
  286.  {
  287.   Int2     type;    /* internal use only */
  288.   Nat4     save;    /* internal use only */
  289.   Nat4     use;    /* number of references */
  290.   Nat4     length; /* length of list  */
  291.   C_object    *data[];
  292.  } *C_list;
  293.  typedef struct      /* C_string - COMPILED XPrims */
  294.  {
  295.   Int2    type;    /* internal use only */
  296.   Nat4    save;    /* internal use only */
  297.   Nat4    use;    /* number of references */
  298.   Nat4    length; /* length of string */
  299.   Nat1    text[];
  300.  } *C_string;
  301.  
  302.  typedef struct      /* C_instance - COMPILED XPrims */
  303.  {
  304.   Int2     type;    /* internal use only */
  305.   Nat4     save;    /* internal use only */
  306.   Nat4     use;    /* number of references */
  307.   C_object    *attrs[];
  308.  } *C_instance;
  309.  
  310.  typedef struct    /* C_Point - COMPILED XPrims */
  311.  {
  312.   Int2    type;     /* internal use only */       
  313.   Nat4    save;     /* internal use only */      
  314.   Nat4    use;     /* number of references */      
  315.   Point    value;
  316.  } *C_Point;
  317.  
  318.  typedef struct    /* C_Ptr - COMPILED XPrims */
  319.  {
  320.   Int2    type;     /* internal use only */       
  321.   Nat4    save;     /* internal use only */      
  322.   Nat4    use;     /* number of references */    
  323.   Int2    reftype    /* Compiled only */     
  324.   Ptr    value;
  325.  } *C_Ptr;
  326.  
  327.  typedef struct    /* C_Handle - COMPILED XPrims */
  328.  {
  329.   Int2    type;     /* internal use only */       
  330.   Nat4    save;     /* internal use only */      
  331.   Nat4    use;     /* number of references */    
  332.   Int2    reftype    /* Compiled only */     
  333.   Handle    value;
  334.  } *C_Handle;
  335.  
  336. Data Types in XCode*530*
  337.  
  338. This section describes C declarations of the Prograph data types for XCode. Two sets of declarations are shown, the second of which uses THINK 4.0 C object extensions. If you are using MPW C or THINK 3.0 C (or if you are using THINK 4.0 C and don窶冲 wish to take advantage of objects) then the first set of declarations apply.
  339.  
  340. XCode declarations:  *530*
  341.  
  342.  typedef struct      /* C_object - XCode */
  343.  {
  344.   Int2    type;    /* internal use only */
  345.   Nat4    save;    /* internal use only */
  346.   Nat4    use;    /* number of references */
  347.  }  *C_object;
  348.  
  349.  typedef struct      /* C_none - XCode */    
  350.  {
  351.   Int2    type;    /* internal use only */
  352.   Nat4    save;    /* internal use only */
  353.   Nat4    use;    /* number of references */
  354.  } *C_none;
  355.  
  356.  typedef struct      /* C_undefined - XCode */
  357.  {
  358.   Int2    type;    /* internal use only */
  359.   Nat4    save;    /* internal use only */
  360.   Nat4    use;    /* number of references */
  361.  } *C_undefined;
  362.  
  363.  typedef struct      /* C_boolean - XCode */
  364.  {
  365.   Int2    type;    /* internal use only */
  366.   Nat4    save;    /* internal use only */
  367.   Nat4    use;    /* number of references */
  368.   Bool    value;
  369.  } *C_boolean;
  370.  
  371.  typedef struct      /* C_integer - XCode */
  372.  {
  373.   Int2    type;    /* internal use only */
  374.   Nat4    save;    /* internal use only */
  375.   Nat4    use;    /* number of references */
  376.   Int4     value;
  377.  } *C_integer;
  378.  
  379.  typedef struct      /* C_real - XCode */
  380.  {
  381.   Int2    type;    /* internal use only */
  382.   Nat4    save;    /* internal use only */
  383.   Nat4    use;    /* number of references */
  384.   Real10    value;
  385.  } *C_real;
  386.  typedef struct      /* C_list - XCode */
  387.  {
  388.   Int2     type;    /* internal use only */
  389.   Nat4     save;    /* internal use only */
  390.   Nat4     use;    /* number of references */
  391.   Nat4     length; /* length of list  */
  392.   C_object    *data[];
  393.  } *C_list;
  394.  typedef struct      /* C_string - XCode */
  395.  {
  396.   Int2    type;    /* internal use only */
  397.   Nat4    save;    /* internal use only */
  398.   Nat4    use;    /* number of references */
  399.   Nat4    length; /* length of string */
  400.   Nat1    text[];
  401.  } *C_string;
  402.  
  403.  typedef struct      /* C_instance - XCode */
  404.  {
  405.   Int2     type;    /* internal use only */
  406.   Nat4     save;    /* internal use only */
  407.   Nat4     use;    /* number of references */
  408.   C_object    *attrs[];
  409.  } *C_instance;
  410.  
  411.  typedef struct    /* C_Point - XCode */
  412.  {
  413.   Int2    type;     /* internal use only */       
  414.   Nat4    save;     /* internal use only */      
  415.   Nat4    use;     /* number of references */      
  416.   Point    value;
  417.  } *C_Point;
  418.  
  419.  typedef struct    /* C_Ptr - XCode */
  420.  {
  421.   Int2    type;     /* internal use only */       
  422.   Nat4    save;     /* internal use only */      
  423.   Nat4    use;     /* number of references */    
  424.   Int2    reftype    /* type of Ptr */     
  425.   Ptr    value;
  426.  } *C_Ptr;
  427.  
  428.  typedef struct    /* C_Handle - XCode */
  429.  {
  430.   Int2    type;     /* internal use only */       
  431.   Nat4    save;     /* internal use only */      
  432.   Nat4    use;     /* number of references */    
  433.   Int2    reftype    /* type of Handle */     
  434.   Handle    value;
  435.  } *C_Handle; 
  436.  
  437.  
  438. XCode THINK C object declarations:  *532*
  439.  
  440.  struct C_object :   indirect     /* C_object - XCode OBJECT C */
  441.  {
  442.                /* type field is hidden */
  443.   Nat4     save;          /* internal use only */
  444.   Nat4     use;          /* count of references */
  445.  }
  446.  
  447.  struct C_none :   C_object      /* C_none - XCode OBJECT C */
  448.  { 
  449.  }; 
  450.  
  451.  struct C_boolean :   C_object     /* C_boolean-XCode OBJECT C */
  452.  {
  453.   Bool    value;
  454.  };
  455.  
  456.  struct C_number :   C_object     /* C_number - XCode OBJECT C */
  457.  {
  458.  };    
  459.  
  460.  struct C_integer :   C_number     /* C_integer-XCode OBJECT C */
  461.  {
  462.   Int4     value;
  463.  };
  464.  
  465.  struct C_real :   C_number      /* C_real - XCode OBJECT C */
  466.  {
  467.   Real10    value; 
  468.  };
  469.  
  470.  struct C_list :   C_object       /* C_list - XCode OBJECT C */
  471.  {
  472.   Nat4     length; 
  473.   C_object    *data[];
  474.  };
  475.  
  476.  struct C_string :   C_object     /* C_string-XCode OBJECT C */
  477.  {
  478.   Nat4    length; 
  479.   Nat1    text[];
  480.  };
  481.  
  482.  struct    C_instance :    C_object    /* C_instance-XCode OBJECT C */
  483.  {
  484.   C_object    *attrs[];
  485.  };
  486.  
  487.  struct C_macintosh :   C_object    /* C_macintosh-XCode OBJECT C */
  488.  {
  489.  };
  490.  
  491.  struct C_Point:   C_macintosh     /* C_Point - XCode OBJECT C */
  492.  {      
  493.   Point    value;
  494.  };
  495.  
  496.  struct C_Ptr:   C_macintosh      /* C_Ptr - XCode OBJECT C */
  497.  {     
  498.   Int2     type;           /* type of Ptr */
  499.   Ptr       value;
  500.  };
  501.  
  502.  struct C_Handle:   C_macintosh      /* C_Handle - XCode OBJECT C */
  503.  {     
  504.   Int2     type;           /* type of handle */
  505.   Handle      value;
  506.  };
  507.  
  508.  Use Counts *533*
  509.  
  510. Prograph is a dataflow language.  Whereas traditional programming languages rely on the storage of data in variables, Prograph treats data items as constants.  This allows the same data item to be shared by multiple processes.  Data can be created, used, and destroyed, but it can never be altered. 
  511.  
  512. The use field in every data item, also known as the use count, contains the number of references to that item.  When writing primitives, it is important to understand and properly maintain the use count.
  513.  
  514. When the use count of a data item falls to zero, Prograph automatically releases the memory occupied by that item.  If you don窶冲 increment a use count appropriately, Prograph may destroy an item that is still referenced. If you fail to decrement a use count appropriately, a data item will continue to occupy space after it is no longer needed.
  515.  
  516. Whenever a new reference is made to a data item, the use count of the item must be incremented.  You can do so by passing the item to the IncUse function.*534*
  517. Whenever a reference to a data item is removed, you must decrement its use count by passing the item to the DecUse function.  You should never decrement the use field directly.
  518.  
  519. In a Prograph program, there are four places where references can be made to data items:    the value of an output root, the attribute slot of an instance, the data slot of a list, and the value of a persistent.
  520.  
  521. You could write a primitive, for instance, that takes a string as input, adds the string to a list, and returns the string as output. The string has a certain use count when it is passed to your primitive (and may be referenced by many other operations). When you assign the string to the list, this constitutes an additional reference, so you must increment the string窶冱 use count. When you pass the string out, that is another reference, and the use count must be incremented once again.
  522.  
  523. Two of the Prograph data types are an exception to the 窶從o alteration窶 rule.  Lists and instances of user-defined classes are considered memory-based structures, and the data in their slots can be replaced with different data items.*534*
  524.  
  525. CAUTION:    The size of C_list data items should not be altered. You should instead make a copy of the C_list using the Duplicate function and then manipulate the copy. 
  526.  
  527. To replace the value of a data slot, first assign the current value of the slot to a temporary variable. Then pass the replacing value to the IncUse function and assign it to the data slot. Finally, pass the value in the temporary variable to the DecUse function. 
  528.  
  529. Always call IncUse before DecUse. When the value of a data slot is being replaced it may be that the current data item is the same as the replacing data item. If DecUse is called first and the data item窶冱 use count is one then DecUse will release the memory occupied by the data item. Calling IncUse before DecUse ensures against unintended destruction of data items.
  530.  
  531. Functions are supplied for creating all of the Prograph data types, as well as for the Macintosh-specific types C_Handle, C_Ptr, C_Point, C_Rect, and C_RGBColor.  When you use these functions to create a data item, the use count is automatically set to one.*534*
  532.  
  533. If your primitive does not place the data item in an output root, list, instance or persistent, no permanent reference is made to that item.  In this case, simply pass the item to the DecUse function so that its memory can be reclaimed.*535*
  534.  
  535. If your primitive makes a single permanent reference to the item窶廃assing it out of the primitive, or assigning it to a list, for example窶琶t is not necessary to increase the use count.
  536.  
  537. A number of functions are also supplied for manipulating lists and instances.  Each of these functions accept flags specifying whether or not to automatically adjust the uses counts.  If the data item being assigned to a list or an instance is created within your primitive, and will not be passed to an output root, it is not necessary to increment the use count.  Conversely, if a data item contained in a list or in an instance is to be output from the primitive without being removed from the list or instance, this new reference requires that the item窶冱 use count be incremented.
  538.  
  539.  Arity Macros *535*
  540.  
  541. The register D0 is used to pass the actual arity to a method. In interpreted code this must always be done. In compiled code it is necessary before any variable-arity method is called. A number of useful macros are provided for the purpose of accessing and setting the arity. 
  542.  
  543. GETARITY(A,B) GETARITY returns the inarity (number of inputs) in A and the outarity (number of outputs) in B.    
  544.  
  545. GETINARITY(A) GETINARITY returns the inarity in A.    
  546.  
  547. GETOUTARITY(A) GETOUTARITY returns the outarity in A.    
  548.  
  549. VARITY(A,B,C,D,E ) VARITY is used in methods with a varying number of inputs and outputs. You pass the first data argument in A, and it returns the input arity in B, the output arity in C, the array of input arguments in D, and the array of pointers to output arguments in E. 
  550.  
  551. SETARITY(A,B) SETARITY places the inarity and outarity passed in A and B into register D0.     *535*
  552.  
  553. The macros which get the arity should be the first thing called in your function since the value of register D0 may change. Also use only one of the get arity macros in any one function.
  554.